package com.GraduationDesign.backend.controller.diff;

import com.GraduationDesign.backend.bl.codeQuality.CodeQualityService;
import com.GraduationDesign.backend.bl.codeReview.ReviewService;
import com.GraduationDesign.backend.bl.diff.DiffService;
import com.GraduationDesign.backend.po.DiffFileList;
import com.GraduationDesign.backend.po.LinkInfo;
import com.GraduationDesign.backend.po.TempList;
import com.GraduationDesign.backend.vo.CodeChangeInfo;
import com.GraduationDesign.backend.vo.CommentVO;
import com.GraduationDesign.backend.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
 * @author: wzx
 * @date: 2022/4/16
 */
@RestController
@RequestMapping("/api/diff")
public class DiffController {
    @Autowired
    DiffService diffService;
    @Autowired
    ReviewService reviewService;
    @Autowired
    CodeQualityService codeQualityService;

    @GetMapping("/get_file_list")
    public ResponseVO getGroupList(@RequestParam("reviewId") Integer reviewId){
        System.out.println("连接成功");
        return ResponseVO.buildSuccess(diffService.getGroupList(reviewId));
    }
    @GetMapping("/get_result_list")
    public ResponseVO getCodeList(@RequestParam("path") String path, @RequestParam("group") Integer groupId,@RequestParam("reviewId")Integer reviewId){
        return ResponseVO.buildSuccess(diffService.getTempList(path,groupId,reviewId));
    }
    @PostMapping("/add_comment")
    public ResponseVO addComment(@RequestBody CommentVO commentVO){
        Date getDate= Calendar.getInstance().getTime();
        String dateStr=new SimpleDateFormat("yyyy-MM-dd HH:mm").format(getDate);
        commentVO.setCreateTime(dateStr);
        return reviewService.addCodeComment(commentVO);
    }
    @GetMapping("/get_files")
    public ResponseVO getFiles(@RequestParam("reviewId") Integer reviewId, @RequestParam("path") String path){
        return ResponseVO.buildSuccess(diffService.getDiffFiles(reviewId, path));
    }
    @GetMapping("/get_link")
    public ResponseVO getLink(@RequestParam("reviewId")Integer reviewId, @RequestParam("codeId") Integer codeId){
        return ResponseVO.buildSuccess(diffService.getLinkInfo(reviewId,codeId));
    }

    @GetMapping("/get_quality")
    public ResponseVO getQuality(@RequestParam("reviewId")Integer reviewId, @RequestParam("filename") String filename){
        return ResponseVO.buildSuccess(codeQualityService.getCodeQuality(reviewId, filename));
    }
    @PostMapping("/change_group")
    public ResponseVO changeGroup(@RequestBody CodeChangeInfo codeChangeInfo){
        return diffService.updateCodeGroup(codeChangeInfo);
    }


}
